//
//  WmcAzimuthAngleLabel.swift
//  YPWatermarkCamera
//
//  Created by 赵新 on 2022/7/21.
//

import UIKit

public extension WmcAzimuthAngleLabel {
    enum Format: Int {
        case `default`
    }
}

// MARK: - [WmcAzimuthAngleLabel]

open class WmcAzimuthAngleLabel: WmcBaseSystemFieldLabel {
    // Open

    /// 显示格式
    open var format: Format = .default {
        didSet { showText() }
    }

    /// 配置
    override open func config() {
        text = "获取罗盘中..."

        // 开始订阅
        WmcCLLocationManager.shared.azimuthAngleRelay.subscribe(onNext: { [weak self] value in
            guard let weakSelf = self,
                  !weakSelf.styleMode.isStatic else { return }
            weakSelf.updateAzimuthAngle(value)
        }).disposed(by: rx.disposeBag)
    }

    // Internal

    var currentAngle: Double = 0

    /// 子类获取时间的方法
    func updateAzimuthAngle(_ angle: Double) {
        YPGCD.Main { [weak self] in
            guard let weakSelf = self else { return }
            weakSelf.currentAngle = angle
            weakSelf.showText()
        }
    }

    /// 显示文字
    func showText() {
        // 直接转format
        var str = ""
        switch format {
        case .`default`:
            str = WmcWatermarkUtil.azimuthAngleDefaultDescribe(currentAngle)
        }
        text = str
    }

}
